<include file="Public/head" title="建议与反馈"/>
<include file="Public/back_head"/>
<div class="main">
<form id="dataForm" onsubmit="return false;">
    <div class="Problem">
        <div class="title">问题描述</div>
        <label for="">
            <textarea name="content" id="jy" cols="30" rows="10" placeholder="请您在此描述详细问题"></textarea>
            <span><i class="Max_num">0</i>/300</span>
        </label>
    </div>
    <div class="up_img">
        <div class="title">上传照片</div>
        <div class="content clear" id="image_list">
            <!--上传图片-->
            <label for="" id="upload_image">
                <i class="iconfont icon-plus" style="background-image: url(__PUBLIC__/home/image/bike_show2.jpg)"></i>
            </label>
            <!--上传图片-->
        </div>
    </div>
    <div class="Prompt"><i class="iconfont icon-zhuyi"></i>为了帮助我们更好的解决问题，请上传清晰商品清晰照片,最多6张。</div>
    <div class="recharge">
        <button class="save_btn" onclick="save()">提交</button>
    </div>
    <div class="empty"></div>
    </form>
</div>
<script type="text/javascript">
    (function () {
        $(function () {
            $("textarea").change(function () {
                var that = this;
                var shuzi=$(this).val().length;
                if(shuzi<=300){
                    $(".Max_num").html(shuzi);
                }else{
                    $(".Max_num").html(300);
                    var str=$(that).val();
                    $(that).val(str.slice(0,300));
                }
            });
            // var n=1;
            // $(".content input[type=file]").change(function () {
            //     var index=$(this).index();
            //     $(".content label").eq(n+1).removeClass("hide");
            //     n++;
            // })
        })
    })(jQuery)
</script>

<script>
        var is_sub = false;
        function save() {
            if (is_sub) {
                return false;
            } else {
                is_sub = true;
            }
            var jy = $('#jy').val();
            if(jy == ''){
                layer.msg('内容不能为空'),time(1500);
                return false;
            }
            $.post("{:U('proposal')}",$('#dataForm').serialize(), function(data) {
                if(data.status == '1'){
                    layer.msg(data.info);
                    setTimeout("location.href='"+data.url+"'",1000);
                }else{
                    layer.msg(data.info);
                }
            });
        }
    </script>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    wx.config({
        debug : false,
        appId : "{$signPackage['appId']}", // 必填，公众号的唯一标识
        timestamp:"{$signPackage['timestamp']}", // 必填生成签名的时间戳
        nonceStr : "{$signPackage['nonceStr']}", // 必填生成签名的随机串
        signature : "{$signPackage['signature']}",// 必填签名，见附录1
        jsApiList : [ 'getLocation', 'checkJsApi', 'chooseImage',
                'uploadImage', 'downloadImage', 'previewImage' ]
    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });
        wx.ready(function() {
                    document.querySelector('#upload_image').onclick = function() {
                        var images = {
                            localId : [],
                            serverId : []
                        };
                        if ($("input[name='localId[]']").length >= 6) {
                            layer.open({
                                content : '仅限6张照片',
                                skin : 'msg',
                                time : 2
                            });
                            return false;
                        }

        wx.chooseImage({
            count : 6 - $("input[name='localId[]']").length, // 默认9
            sizeType : [ 'compressed' ],
            sourceType : [ 'album', 'camera' ],
            success : function(res) {
                var localIds = res.localIds;
                var i = 0, length = localIds.length;
                function upload() {
                    wx.uploadImage({
                    localId : localIds[i].toString(),
                    success : function(res) {
                        var str = '';
                        var localData = '';
                        //判断是否是苹果
                        var ua = window.navigator.userAgent.toLowerCase();
                        var s = ua.match(/IPhone/i);
                        str = '';
                        if(s){
                            wx.getLocalImgData({
                                localId: localIds[i].toString(), // 图片的localID
                                success: function (ress) {                                   
                                  localData = ress.localData; // localData是图片的base64数据，可以用img标签显示
                                  str += ' <label for="" class="upload" style="display: block;width: 10%;height: 6rem;position: float: left; margin-left:40px;">';
                                  str += ' <img src="'+localData+'" style="width:300px;height:50px;">';
                                 
                                  str += "<input name='image_name[]' type='hidden' value='" + res.serverId + "' />";
                                  str += '<a href="javascript:;" style="z-index:100;" onclick="$(this).parents(\'.upload\').remove()" >x</a>';
                                  str += '</label>';
                                  $('#image_list').before(str);
                                }
                              });
                        }else{
                            str += ' <label for="" class="">';
                            str += ' <i class="iconfont icon-plus" style="background-image: url('+localIds[i].toString()+')"></i>';
                            str += "<input name='image_name[]' type='hidden' value='" + res.serverId + "' />";           
                            str += '<a href="javascript:;" style="z-index:100;" onclick="$(this).parents(\'.upload\').remove()" >x</a>';
                            str += '</label>';
                            $('#image_list').before(str);
                           }
                        i++;
                        if (i < length) {
                            upload();
                        }
                    },
                    fail : function(res) {
                        layer.msg(JSON.stringify(res));
                    }
                });
                }
            upload();
            }
        });
    };
});
    </script>
<include file="Public/foot"/>